package com.ww.springstudy.config.fullOrLite;

import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Component  //说明这是一个lite模式和
public class LiteConfig {

    @Bean
    public Student stuA() {
        Student stu = new Student();
        stu.setName("stuA");
        return stu;
    }

    @Bean
    private Student stuB() { //1.可以是private的方法
        Student stu = new Student();
        stu.setName("stuB");

        //2.lite模式下:调用stuA()方法会生成一个新的Bean
        System.out.println("stuB1:" + System.identityHashCode(stuA()));
        System.out.println("stuB2:" + System.identityHashCode(stuA()));
        System.out.println("stuB3:" + (stuA() == stuA())); //返回false

        return stu;
    }

    //内部类可以是任意模式
    private static class InnerConfig {
        @Bean
        //lit模式下方法可以使用private final修饰
        private final Student stuInner() {
            Student stu = new Student();
            stu.setName("stuInner");
            return stu;
        }
    }

}